create table sys_dept
(
    dept_id     bigint identity (100, 1)
        constraint PK__sys_dept__DCA65974EF6572B7
            primary key,
    parent_id   bigint
        constraint DF_sys_dept_parent_id default 0,
    ancestors   nvarchar(50)
        constraint DF_sys_dept_ancestors default '',
    dept_name   nvarchar(30)
        constraint DF_sys_dept_dept_name default '',
    order_num   int
        constraint DF_sys_dept_order_num default 0,
    leader      nvarchar(20),
    phone       nvarchar(11),
    email       nvarchar(50),
    status      nchar
        constraint DF_sys_dept_status default '0',
    del_flag    nchar
        constraint DF_sys_dept_del_flag default '0',
    create_by   nvarchar(64)
        constraint DF_sys_dept_create_by default '',
    create_time datetime2(0),
    update_by   nvarchar(64)
        constraint DF_sys_dept_update_by default '',
    update_time datetime2(0)
)
go

exec sp_addextendedproperty 'MS_Description', '部门表', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept'
go

exec sp_addextendedproperty 'MS_Description', '部门id', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'dept_id'
go

exec sp_addextendedproperty 'MS_Description', '父部门id', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'parent_id'
go

exec sp_addextendedproperty 'MS_Description', '祖级列表', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'ancestors'
go

exec sp_addextendedproperty 'MS_Description', '部门名称', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'dept_name'
go

exec sp_addextendedproperty 'MS_Description', '显示顺序', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'order_num'
go

exec sp_addextendedproperty 'MS_Description', '负责人', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'leader'
go

exec sp_addextendedproperty 'MS_Description', '联系电话', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'phone'
go

exec sp_addextendedproperty 'MS_Description', '邮箱', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'email'
go

exec sp_addextendedproperty 'MS_Description', '部门状态（0正常 1停用）', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'status'
go

exec sp_addextendedproperty 'MS_Description', '删除标志（0代表存在 2代表删除）', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN',
     'del_flag'
go

exec sp_addextendedproperty 'MS_Description', '创建者', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'create_by'
go

exec sp_addextendedproperty 'MS_Description', '创建时间', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'create_time'
go

exec sp_addextendedproperty 'MS_Description', '更新者', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'update_by'
go

exec sp_addextendedproperty 'MS_Description', '更新时间', 'SCHEMA', 'dbo', 'TABLE', 'sys_dept', 'COLUMN', 'update_time'
go

INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (100, 0, N'0', N'若依科技', 0, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (101, 100, N'0,100', N'深圳总公司', 1, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (102, 100, N'0,100', N'长沙分公司', 2, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (103, 101, N'0,100,101', N'研发部门', 1, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (104, 101, N'0,100,101', N'市场部门', 2, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (105, 101, N'0,100,101', N'测试部门', 3, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (106, 101, N'0,100,101', N'财务部门', 4, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (107, 101, N'0,100,101', N'运维部门', 5, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (108, 102, N'0,100,102', N'市场部门', 1, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);
INSERT INTO [ry-vue].dbo.sys_dept (dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time) VALUES (109, 102, N'0,100,102', N'财务部门', 2, N'若依', N'15888888888', N'ry@qq.com', N'0', N'0', N'admin', N'2021-12-03 22:22:12', N'', null);